# Contributor: Mathew Meins <mm@blackhelicopters.net>
# Maintainer: Mathew Meins <mm@blackhelicopters.net>
pkgname=olsrd
pkgver=0.9.8
pkgrel=2
pkgdesc="An implementation of the IETF RFC 3626: Optimized Link State Routing Protocol"
url="http://www.olsr.org/mediawiki/index.php/Olsr_Daemon"
arch="all"
license="BSD-3-Clause"
makedepends="linux-headers flex bison"
subpackages="$pkgname-openrc $pkgname-doc $pkgname-plugins"
source="https://github.com/OLSR/olsrd/archive/v$pkgver/olsrd-$pkgver.tar.gz
	bison.patch
	musl.patch
	olsrd.initd
	olsrd.confd
	"
options="!check" # No test suite provided by upstream

build() {
	# build olsrd itself
	make all

	# build olsr_switch
	make switch

	# build plugins
	for plugin in arprefresh bmf dot_draw dyn_gw dyn_gw_plain httpinfo \
		jsoninfo mdns nameservice netjson p2pd pgraph poprouting \
		quagga secure sgwdynspeed txtinfo watchdog; do
			make -C $builddir/lib/$plugin
	done
}

package() {
	install -m755 -D "$builddir"/olsrd \
		"$pkgdir"/usr/sbin/olsrd
	install -m755 -D "$builddir"/olsr_switch \
		"$pkgdir"/usr/sbin/olsr_switch
	install -m644 -D "$builddir"/files/olsrd.conf.default.txt \
		"$pkgdir"/etc/$pkgname/olsrd.conf
	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

doc() {
	# man pages
	install -m644 -D "$builddir"/files/olsrd.8.gz \
		"$subpkgdir"/usr/share/man/man8/olsrd.8.gz
	install -m644 -D "$builddir"/files/olsr_switch.8.gz \
		"$subpkgdir"/usr/share/man/man8/olsr_switch.8.gz
	install -m644 -D "$builddir"/files/olsrd.conf.5.gz \
		"$subpkgdir"/usr/share/man/man5/olsrd.conf.5.gz

	# miscellaneous docs
	for f in README olsrd.conf.commotion olsrd.conf.default \
		olsrd.conf.default.lq olsrd.conf.default.rfc \
		olsrd.conf.default.txt olsrd.conf.funkfeuer olsrd.ufw.profile \
		generateEffectiveConfigurationFile olsrd-adhoc-setup \
		sgw_policy_routing_setup.sh; do
			install -m644 -D "$builddir"/files/$f \
				"$subpkgdir"/usr/share/doc/$pkgname/$f
	done
}

plugins() {
	pkgdesc="Optional plugins for olsrd"

	find "$builddir"/lib/ -name 'olsrd_*.so.*' -exec sh -c '
		install -m755 -D "$1" "$subpkgdir"/usr/lib/$(basename $1)
	' sh {} \;
}

sha512sums="cf3066310c4ea644ba1f482e847aa073ad006000308bfa993cecda4ccf4e9919a9005680b3c1d98e34f0c13818213f208e8dc93c8b060eeaaac160fc3df4ce8c  olsrd-0.9.8.tar.gz
b8c44fce64fd946459c67ea130b7230fbb88a761d5b64221303adea2a6ddf074c39521f22aade27820bff8748ba50851d9cbf7602c10d6bd9615992284cb2046  bison.patch
1d2f74d017e50d17c4eabbf52412e2f5aeec7bb2ca0bb1738ae8c0527b9abd13299cbebb3428db1cc95d574b86eea50cec8c4cf388f18d6723577800fd6678fb  musl.patch
9051d65c0f3fdc82ceccc622062a5ffa7accc6584030c0e5ba855e7a7f478233476bc44ca12fa68b5c391000f0e9d4c3198bcdd879d549ae83c37d0301bec785  olsrd.initd
4f84d8738ff00d12ca36a1b00f4c0b7b71128be60aa895a8d337d31732ed8b5bd7f9a6f0892b0218584d25630c110e8763a1605065a1ef8111b9f13299fffedb  olsrd.confd"
